﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class tbvisistorDAL : SqlDataProvider
    {
        #region[tbvisistor_GetById]
        public List<tbvisistor> tbvisistor_GetById(string Id)
        {
            List<Entity.tbvisistor> list = new List<Entity.tbvisistor>();
            using (SqlCommand dbCmd = new SqlCommand("sp_tbvisistor_GetById", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(tbvisistor.tbvisistorIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[tbvisistor_GetByTop]
        public List<tbvisistor> tbvisistor_GetByTop(string Top, string Where, string Order)
        {
            List<Entity.tbvisistor> list = new List<Entity.tbvisistor>();
            using (SqlCommand dbCmd = new SqlCommand("sp_tbvisistor_GetByTop", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(tbvisistor.tbvisistorIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[tbvisistor_GetByAll]
        public List<tbvisistor> tbvisistor_GetByAll()
        {
            List<Entity.tbvisistor> list = new List<Entity.tbvisistor>();
            using (SqlCommand dbCmd = new SqlCommand("sp_tbvisistor_GetByAll", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(tbvisistor.tbvisistorIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[tbvisistor_Paging]
        public List<tbvisistor> tbvisistor_Paging(string CurentPage, string PageSize)
        {
            List<Entity.tbvisistor> list = new List<Entity.tbvisistor>();
            using (SqlCommand dbCmd = new SqlCommand("sp_tbvisistor_Paging", GetConnection()))
            {

                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@CurentPage", CurentPage));
                dbCmd.Parameters.Add(new SqlParameter("@PageSize", PageSize));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(tbvisistor.tbvisistorIDataReader(dr));
                    }
                }
                dr.Close();

            }
            return list;
        }
        #endregion
        #region[tbvisistor_Insert]
        public bool tbvisistor_Insert(tbvisistor data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbvisistor_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("tbvisistor");
            return true;
        }
        #endregion
        #region[tbvisistor_Update]
        public bool tbvisistor_Update(tbvisistor data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbvisistor_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@iuseronline", data.iuseronline));
                dbCmd.Parameters.Add(new SqlParameter("@ivisistor", data.ivisistor));
                dbCmd.Parameters.Add(new SqlParameter("@iuseronlinedate", data.iuseronlinedate));
                dbCmd.Parameters.Add(new SqlParameter("@dateonline", data.dateonline));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("tbvisistor");
            return true;
        }
        #endregion
        #region[Reset_useronline]
        public bool Reset_useronline(tbvisistor data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Reset_useronline", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("tbvisistor");
            return true;
        }
        #endregion
        #region[Update_useronline]
        public bool Update_useronline(tbvisistor data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Update_useronline", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("tbvisistor");
            return true;
        }
        #endregion
        #region[Get_useronlinedate]
        public bool Get_useronlinedate(tbvisistor data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Get_useronlinedate", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("tbvisistor");
            return true;
        }
        #endregion
        #region[userofline]
        public bool userofline(tbvisistor data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_userofline", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("tbvisistor");
            return true;
        }
        #endregion
        #region[tbvisistor_Delete]
        public bool tbvisistor_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbvisistor_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("tbvisistor");
            return true;
        }
        #endregion

    }
}
